#ifndef _UTIL_COMPAT_H_
#define _UTIL_COMPAT_H_

// This file tries to make up for some of the critical differences between
//   * Posix and Windows
//   * MSVC and GCC
// in terms of
//   * defining the integer types
//   * making sure std::min and std::max exist
//   * making sure #if __BYTE_ORDER == __LITTLE_ENDIAN etc work

#ifdef WIN32
#	define NOMINMAX
#	define WIN32_LEAN_AND_MEAN
#	include <windows.h>
#	include <winsock2.h>
	typedef signed char int8;
	typedef signed short int16;
	typedef signed int int32;
	typedef signed long long int64;
	typedef unsigned char uint8;
	typedef unsigned short uint16;
	typedef unsigned int uint32;
	typedef unsigned long long uint64;
#else
#	include <unistd.h>
#	include <endian.h>
#	include <errno.h>
#	include <arpa/inet.h>
#	include <inttypes.h>
	typedef int64_t int64;
	typedef int32_t int32;
	typedef int16_t int16;
	typedef int8_t int8;
	typedef uint64_t uint64;
	typedef uint32_t uint32;
	typedef uint16_t uint16;
	typedef uint8_t uint8;
#endif

#ifdef min
#	undef min
#endif
#ifdef max
#	undef max
#endif
#ifndef NULL
#	define NULL 0
#endif

template<typename T>
T min(T a, T b) {
	if(a < b) return a;
	return b;
}

template<typename T>
T max(T a, T b) {
	if(a > b) return a;
	return b;
}


// Endianess
#ifdef WIN32
#	define __BYTE_ORDER 1
#	define __LITTLE_ENDIAN 1
#	define __BIG_ENDIAN 999
#else
#	include <endian.h>
#endif



#endif
